package com.zzyl.controller;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingProjectDto;
import com.zzyl.entity.NursingProject;
import com.zzyl.service.NursingProjectService;
import com.zzyl.vo.NursingProjectVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/nursing_project")
@Api(tags = "护理项目管理")
public class NursingProjectContorller {

    @Autowired
    private NursingProjectService nursingProjectService;
    @GetMapping()
    @ApiOperation("分页查询护理项目列表")
    public ResponseResult<PageResponse<NursingProjectVo>> getByPage(
       @ApiParam(value = "护理项目名称") String name,
       @ApiParam(value = "状态：0-禁止 1-启用") Integer status,
       @ApiParam(value = "当前页码") @RequestParam(value = "pageNum",defaultValue = "1") Integer pageNum,
       @ApiParam(value = "每页展示数量") @RequestParam(value = "pageSize",defaultValue="10") Integer pageSize

    ){
        PageResponse<NursingProjectVo> nursingProjectPageInfo = nursingProjectService.getByPage(name, status, pageNum, pageSize);
        return ResponseResult.success(nursingProjectPageInfo);
    }

    @PostMapping
    @ApiOperation("添加护理项目")
    public ResponseResult add(@RequestBody NursingProjectDto nursingProjectDto){
        nursingProjectService.add(nursingProjectDto);
        return ResponseResult.success();
    }
   @GetMapping("/{id}")
   @ApiOperation("护理项目页面回显")
    public ResponseResult<NursingProjectVo> getById(@PathVariable Long id){
      NursingProjectVo nursingProjectVo= nursingProjectService.getById(id);
       return ResponseResult.success(nursingProjectVo);
    }
    @PutMapping
    @ApiOperation("护理项目修改编辑")
    public ResponseResult update(@RequestBody NursingProjectDto nursingProjectDto){
        nursingProjectService.update(nursingProjectDto);
        return ResponseResult.success();
    }
    @DeleteMapping("/{id}")
    @ApiOperation("删除护理项目")
    public ResponseResult <NursingProjectVo> deleteById(@PathVariable Long id){
        nursingProjectService.deleteById(id);
        return ResponseResult.success();
    }
    @PutMapping("/{id}/status/{status}")
    @ApiOperation("通过id修改状态")
    public ResponseResult updateById(@PathVariable Long id,@PathVariable Integer status){
           nursingProjectService.updateById(id,status);
           return ResponseResult.success();
    }
    @GetMapping("/all")
    public ResponseResult<List<NursingProjectVo>> all(){
        List<NursingProjectVo>nursingProjectVo = nursingProjectService.all();
        return  ResponseResult.success(nursingProjectVo);

    }
}
